package com.ruoyi.heima.service.Impl;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.web.domain.BaseEntity;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.heima.mapper.TbNewsMapper;
import com.ruoyi.heima.domain.News;
import com.ruoyi.heima.service.ITbNewsService;

/**
 * newsService业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-21
 */
@Service
public class TbNewsServiceImpl implements ITbNewsService 
{
    @Autowired
    private TbNewsMapper tbNewsMapper;

    /**
     * 查询news
     * 
     * @param newsId news主键
     * @return news
     */
    @Override
    public News selectTbNewsByNewsId(Long newsId)
    {
        return tbNewsMapper.selectTbNewsByNewsId(newsId);
    }

    /**
     * 查询news列表
     * 
     * @param news news
     * @return news
     */
    @Override
    public List<News> selectTbNewsList(News news)
    {
        return tbNewsMapper.selectTbNewsList(news);
    }

    /**
     * 新增news
     * 
     * @param news news
     * @return 结果
     */
    @Override
    public int insertTbNews(News news)
    {
        news.setCreateTime(DateUtils.getNowDate());
        news.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        return tbNewsMapper.insertTbNews(news);
    }

    /**
     * 修改news
     * 
     * @param news news
     * @return 结果
     */
    @Override
    public int updateTbNews(News news)
    {
        news.setUpdateTime(DateUtils.getNowDate());
        news.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        return tbNewsMapper.updateTbNews(news);
    }

    /**
     * 删除news
     * 
     * @param newsIds 需要删除的news主键
     * @return 结果
     */
    @Override
    public int deleteTbNewsByNewsIds(Long[] newsIds)
    {
//        List<News> news;
//        for (int i = 0; i < newsIds.length; i++)
//        {
//            news = selectTbNewsListById(newsIds[i]);
//            news.get(i).setStatus(3);
//        }
        return tbNewsMapper.deleteTbNewsByNewsIds(newsIds);
    }

    /**
     * 删除news信息
     *
     * @param newsId news主键
     * @return 结果
     */
    @Override
    public int deleteTbNewsByNewsId(Long newsId)
    {
        News news = tbNewsMapper.selectTbNewsByNewsId(newsId);
        news.setStatus(3);
        return tbNewsMapper.deleteTbNewsByNewsId(newsId);
    }

    @Override
    public List<News> selectTbNewsListById(Long newsId) {

        return tbNewsMapper.selectTbNewsListById(newsId);
    }


}
